//
//  NewListDetailTableViewCell.m
//  XWZ_News_Work
//
//  Created by dllo on 16/1/15.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "NewListDetailTableViewCell.h"
#import "TitleCollectionViewCell.h"

@interface NewListDetailTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView *collectionV;
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;

@end

@implementation NewListDetailTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubview];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.collectionV.frame = self.contentView.frame;
     self.layout.itemSize = CGSizeMake((self.collectionV.frame.size.width - 50 * WIDTH) / 4 , 30 * HEIGHT);
   [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
       make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-10);
       make.height.mas_equalTo(@10);
       make.right.equalTo(self.contentView.mas_right).with.offset(-10);
       make.width.mas_equalTo(@150);
       
   }];
    
}

- (void)setArr:(NSMutableArray *)arr
{
    if (_arr != arr) {
        _arr = arr;
    }
    
    [self.collectionV reloadData];
    
}



- (void)createSubview
{
    self.backgroundColor = [UIColor whiteColor];
    [self createCollectionView];
    [self createLabel];
}

- (void)createLabel
{
    self.label = [[UILabel alloc] init];
    self.label.font = [UIFont systemFontOfSize:15.0];
    self.label.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:self.label];
}

- (void)createCollectionView
{
    self.layout = [[UICollectionViewFlowLayout alloc] init];
    self.layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    self.layout.minimumLineSpacing = 5;
    self.layout.minimumInteritemSpacing = 1;
   
    self.layout.sectionInset = UIEdgeInsetsMake(10, 20, 40, 10);
    
    self.collectionV  = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:self.layout];
    self.collectionV.scrollEnabled = NO;
    self.collectionV.delegate = self;
    self.collectionV.dataSource = self;
    self.collectionV.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.collectionV];
    [self.collectionV registerClass:[TitleCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
//    UILongPressGestureRecognizer *longGR = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longGRAction:)];
//    [self.collectionV addGestureRecognizer:longGR];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.arr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    TitleCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];

    cell.label.text = [self.arr objectAtIndex:indexPath.row];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [self.delegate changeListByIndex:indexPath.row];
    [self.dataSource allToDidByIndex:indexPath.row];
}

- (void)longGRAction:(UILongPressGestureRecognizer *)sender
{
    if (UIGestureRecognizerStateBegan == sender.state) {
       
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
